package pv1682010.gui;

import javax.sql.DataSource;
import javax.swing.table.AbstractTableModel;
import pv1682010.Database;
import pv1682010.User;
import pv1682010.UserManager;

/**
 *
 * @author Petr
 */
public class TeachersTableModel extends AbstractTableModel {

    private UserManager um;

    public TeachersTableModel() {
        DataSource ds = new Database();
        um = new UserManager(ds);
    }

    public int getRowCount() {
        int rowCount = 0;
        rowCount = um.getUsers().size();
        return rowCount;
    }

    @Override
    public Class<?> getColumnClass(int columnIndex) {
        if (columnIndex == 0) {
            return Integer.class;
        }
        return Object.class;
    }

    @Override
    public int getColumnCount() {
        return 2;
    }

    @Override
    public String getColumnName(int columnIndex) {
        switch (columnIndex) {
            case 0:
                return "Uco";
            case 1:
                return "Name";
            default:
                throw new IllegalArgumentException("columnIndex");
        }
    }

    public Object getValueAt(int rowIndex, int columnIndex) {
        User user = um.getUsers().get(rowIndex);
        switch (columnIndex) {
            case 0:
                return user.getUco();
            case 1:
                return user.getName();
            default:
                throw new IllegalArgumentException("columnIndex");
        }
    }
}
